<template>
  <div class="container">
    <div class="header">
      <p class="title">我的订单</p>
      <span>请谨防钓鱼诈骗电话，详情了解更多>>></span>
    </div>
    <div class="nav">
      <el-tabs v-model="activeName">
        <el-tab-pane label="全部有效订单" name="all"></el-tab-pane>
        <el-tab-pane label="待支付" name="pending"></el-tab-pane>
        <el-tab-pane label="待收货" name="receiving"></el-tab-pane>
        <el-tab-pane label="已收货" name="received"></el-tab-pane>
      </el-tabs>
    </div>
    <div class="main">
      <el-card class="order-card" v-for="item in dataSource" :key="item.id">
        <template #header>
          <div>
            <div class="status">
              {{
                item.status === 'pending'
                  ? '待支付'
                  : item.status === 'receiving'
                  ? '待收货'
                  : '已收货'
              }}
            </div>
            <div class="order-info">
              <ul>
                <li>{{ item.createTime }}</li>
                <li>{{ item.receiver }}</li>
                <li>订单编号：{{ item.serialNumber }}</li>
                <li>{{ item.pay }}</li>
              </ul>
              <p>
                订单金额：<span>￥{{ item.price * item.number }}</span
                >元
              </p>
            </div>
          </div>
        </template>
        <div class="card-body">
          <div class="good-info">
            <img
              :src="require('@/static/images/personal/' + item.img)"
              alt=""
            />
            <div>
              <p>{{ item.title }}}</p>
              <p>￥{{ item.price }} × {{ item.number }}</p>
            </div>
          </div>
          <div class="btns">
            <el-button type="danger">{{
              item.status === 'pending'
                ? '确认付款'
                : item.status === 'receiving'
                ? '确认收货'
                : '待评价'
            }}</el-button>
            <el-button>订单详情</el-button>
          </div>
        </div>
      </el-card>
    </div>
    <div class="pagination">
      <el-pagination background layout="prev, pager, next" :total="total" />
    </div>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent, toRefs, reactive } from 'vue';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const data = require('@/mock/personal/my-orders.json');

export default defineComponent({
  setup() {
    const state = reactive({
      activeName: 'all',
      pageSize: 10,
      pageNumber: 1,
      total: 0,
    });

    state.pageSize = data.pageSize;
    state.total = data.total;
    const dataSource = computed(() => {
      if (state.activeName === 'all') {
        return data.list;
      }
      let result = data.list.filter((item: any) => {
        return item.status == state.activeName;
      });
      return result;
    });
    return {
      ...toRefs(state),
      dataSource,
    };
  },
});
</script>

<style lang="scss" scoped>
.container {
  width: 100%;
  border: 1px solid #ddd;
  padding: 46px 30px;
}
.header {
  .title {
    font-size: 18px;
    font-weight: 500;
    display: inline-block;
    margin-right: 10px;
  }
  span {
    font-size: 10px;
    color: #666;
  }
}
.main {
  width: 100%;
  .order-card {
    width: 100%;
    box-shadow: none;
    padding: 10px;
    margin-bottom: 20px;
    .status {
      margin-bottom: 10px;
    }
    .order-info {
      display: flex;
      justify-content: space-between;
      font-size: 10px;
      color: #666;
      padding-bottom: 10px;

      ul {
        display: flex;

        li {
          margin-right: 24px;
          position: relative;

          &:not(:last-child)::after {
            content: '';
            display: inline-block;
            position: absolute;
            width: 1px;
            height: 14px;
            right: -10px;
            top: 2px;
            background-color: #666;
          }
        }
      }
    }
    .card-body {
      display: flex;
      justify-content: space-between;

      .good-info {
        display: flex;
        height: 64px;
        padding-top: 10px;
        img {
          height: 100%;
        }

        div {
          margin-left: 1rem;
          font-size: 16px;
          color: #333;
          line-height: 32px;
        }
      }

      .btns {
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        align-content: space-around;
      }
    }
  }
}
.pagination {
  display: flex;
  justify-content: center;
}
::v-deep .el-tabs__nav-wrap::after {
  display: none;
}
::v-deep .el-tabs__item {
  font-size: 16px;
}
::v-deep .el-tabs__item:not(:last-child)::after {
  display: inline-block;
  content: '';
  position: absolute;
  width: 2px;
  height: 16px;
  top: 12px;
  right: 0;
  background-color: #ccc;
}
::v-deep .el-tabs__active-bar {
  display: none;
}
::v-deep .el-card__header {
  padding: 0;
}
::v-deep .el-button {
  width: 100px;
  padding: 0;
  margin: 0;
}
::v-deep .el-card__body {
  padding: 10px;
}
</style>
